package com.stn.zjx.givingtreasure.net.impl;

import android.annotation.SuppressLint;
import android.widget.Toast;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.stn.zjx.givingtreasure.net.PayApi;
import com.stn.zjx.givingtreasure.net.UserApi;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;
import com.vondear.rxtools.view.RxToast;

import org.json.JSONObject;

public class PayNetImpl {



    /**
     * @apiNote 设置支付密码
     * @param token token
     * @param userPrivatepwd 支付密码
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void reset_paypassword(String token, String userPrivatepwd
            , String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userPrivatepwd",userPrivatepwd);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.reset_paypassword)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }


    /**
     * @apiNote 校验支付密码
     * @param token token
     * @param userPrivatepwd 支付密码
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void check_user_paypassword(String token, String userPrivatepwd
            , String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userPrivatepwd",userPrivatepwd);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.check_user_paypassword)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }

    /**
     * @apiNote 检查是否允许进入支付设置界面
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void join_set_user_paypassword(String token,  String tag, StringCallback callback){

        OkGo.<String>post(PayApi.join_set_user_paypassword)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .execute(callback);
    }

    /**
     * @apiNote 用户转账
     * @param token token
     * @param userPrivatepwd 支付密码
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void user_transfer(String token,
                                     String userPrivatepwd,
                                     Integer toUserId,
                                     String userMoney,
                                     String tag,
                                     StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userPrivatepwd",userPrivatepwd);
            jsonObject.put("toUserId",toUserId);
            jsonObject.put("userMoney",userMoney);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.user_transfer)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }



    /**
     * @apiNote 用户余额交易流水
     * @param token token
     * @param pageNow 当前页数
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_user_transfer_record(String token,
                                     Integer pageNow,
                                     Integer pageSize,
                                     String tag,
                                     StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("pageNow",pageNow);
            jsonObject.put("pageSize",pageSize);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.query_user_transfer_record)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }


    /**
     * @apiNote 查询用户交易流水通过交易号
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_user_transfer_record_by_flow_number(String token,
                                                                 String transferFlowNumber,
                                                  String tag,
                                                  StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("transferFlowNumber",transferFlowNumber);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.query_user_transfer_record_by_flow_number)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }

    /**
     * @apiNote 用户余额，充值
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void user_recharge_create_order_no(String token,
                                                      String userPrivatepwd,
                                                                 String subject,
                                                                String body,
                                                     String userMoney,
                                                     Integer payType,
                                                     String userBankCardName,
                                                     String userBankCardNo,
                                                                 String tag,
                                                                 StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userPrivatepwd",userPrivatepwd);
            jsonObject.put("subject",subject);
            jsonObject.put("body",body);
            jsonObject.put("userMoney",userMoney);
            jsonObject.put("payType",payType);
            jsonObject.put("userBankCardName",userBankCardName);
            jsonObject.put("userBankCardNo",userBankCardNo);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.user_recharge_create_order_no)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }


    /**
     * @apiNote 用户余额，提现
     * @param token token
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void user_balance_withdraw(String token,
                                             String userRealName,
                                             String userPhone,
                                             String userIdCard,
                                             String userBankCardName,
                                             String userBankCardNo,
                                             Integer userId,
                                             String userMoney,
                                             String userPrivatepwd,
                                                     String tag,
                                                     StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userRealName",userRealName);
            jsonObject.put("userPhone",userPhone);
            jsonObject.put("userIdCard",userIdCard);
            jsonObject.put("userBankCardName",userBankCardName);
            jsonObject.put("userBankCardNo",userBankCardNo);
            jsonObject.put("userId",userId);
            jsonObject.put("userMoney",userMoney);
            jsonObject.put("userPrivatepwd",userPrivatepwd);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(PayApi.user_balance_withdraw)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }

    /**
     * @apiNote 用户余额，支付配置
     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void get_user_balance_config(

                                             String tag,
                                             StringCallback callback){

        OkGo.<String>post(PayApi.get_user_balance_config)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .execute(callback);
    }
}
